const express = require('express');
const router = express.Router();
const bodyParser = require('body-parser');
const data = require('../data');
const userSQL = require('../../db/userSQL')
const loginSQL = require('../../db/loginSQL')

router.post('/getinfo', bodyParser.json(), (req, res) => {
    // 检查用户ID是否为空
    if (!req.body["userID"]
        || typeof req.body["userID"] != "number") {
        res.json({
            err: 1,
            message: '用户ID为空'
        })
    } else {
        let userID = req.body["userID"];
        loginSQL.getByID(userID, (result) => {
            var userStatus = eval(result)[0].userStatus
            if (userStatus == 0) {
                res.json({
                    err: 3,
                    message: '用户被封禁'
                })
            }
            else {
                userSQL.getinfo(userID, (result) => {
                    var user = result[0]
                    user.err = 200
                    res.json(user)
                })
            }
        })
    }

})

module.exports = router;